#include <cstdio>
#include <algorithm>
#include <vector> //练习
using namespace std;
vector<int> out;
vector<int>::iterator it;
int hashtable[101] = {0};
int seq[101] = {0};
bool cmp(int a, int b)
{
    return a > b;
}
int main()
{
    int K;
    scanf("%d", &K);
    int n;
    int len;
    int i;
    while (K--)
    {
        scanf("%d", &n);
        seq[len++] = n;
        while (n != 1)
        { //读入的同时，记录各个数据得到最终结果的中间过程当中遇到的每一个数
            if (0 == n % 2)
            {
                n /= 2;
            }
            else
            {
                n = (3 * n + 1) / 2;
            }
            if (n <= 100)
                ++hashtable[n];
        }
    }
    for (i = 0; i < len; ++i)
    {
        if (0 == hashtable[seq[i]])
            out.push_back(seq[i]);
    }
    sort(out.begin(), out.end(), cmp);
    for (it = out.begin(); it != out.end(); ++it)
    {
        printf("%d", *it);
        if (it != out.end() - 1)
            putchar(' ');
    }
    putchar('\n');
    return 0;
}